package com.ruoyi.patrol.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 树形结构
 */
@Data
public class TreeStruct {

    /**
     * 节点id
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeStruct> children;

    public TreeStruct() {}

    public TreeStruct(PtCatalog catalog) {
        this.id = catalog.getCatId();
        this.label = catalog.getName();
        this.children = catalog.getChildren().stream().map(TreeStruct::new).collect(Collectors.toList());
    }

}
